<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"movie0125.gitee.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="问题描述UOS企业版 1030版本，Kunpeng920 CPU，部署仓库中ceph 12.2 版本 在部署osd节点时，报错如下 12342021-01-07 16:47:34.722670 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 5180582502021-01-07 16:47:34.726567 ffff98ef41e">
<meta property="og:type" content="article">
<meta property="og:title" content="ceph-crc-failed-at-Kunpeng920">
<meta property="og:url" content="https://movie0125.gitee.io/2021/03/09/ceph-crc-failed-at-Kunpeng920/index.html">
<meta property="og:site_name" content="Movie Blog">
<meta property="og:description" content="问题描述UOS企业版 1030版本，Kunpeng920 CPU，部署仓库中ceph 12.2 版本 在部署osd节点时，报错如下 12342021-01-07 16:47:34.722670 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 5180582502021-01-07 16:47:34.726567 ffff98ef41e">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-09T05:40:16.000Z">
<meta property="article:modified_time" content="2021-03-17T05:23:05.292Z">
<meta property="article:author" content="Movie">
<meta property="article:tag" content="ceph">
<meta property="article:tag" content="crc">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://movie0125.gitee.io/2021/03/09/ceph-crc-failed-at-Kunpeng920/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ceph-crc-failed-at-Kunpeng920 | Movie Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Movie Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">拥抱开源，快乐分享</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://movie0125.gitee.io/2021/03/09/ceph-crc-failed-at-Kunpeng920/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Movie">
      <meta itemprop="description" content="学习，记录，分享，收获">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Movie Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ceph-crc-failed-at-Kunpeng920
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-09 13:40:16" itemprop="dateCreated datePublished" datetime="2021-03-09T13:40:16+08:00">2021-03-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-03-17 13:23:05" itemprop="dateModified" datetime="2021-03-17T13:23:05+08:00">2021-03-17</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" itemprop="url" rel="index"><span itemprop="name">源码分析</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/03/09/ceph-crc-failed-at-Kunpeng920/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/03/09/ceph-crc-failed-at-Kunpeng920/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h1><p>UOS企业版 1030版本，Kunpeng920 CPU，部署仓库中ceph 12.2 版本</p>
<p>在部署osd节点时，报错如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">2021-01-07 16:47:34.722670 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 518058250</span><br><span class="line">2021-01-07 16:47:34.726567 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 518058250</span><br><span class="line">2021-01-07 16:47:34.730363 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 518058250</span><br><span class="line">2021-01-07 16:47:34.734226 ffff98ef41e0  0 bad crc in front 4037982777 !&#x3D; exp 518058250</span><br></pre></td></tr></table></figure>
<a id="more"></a>

<h1 id="问题分析"><a href="#问题分析" class="headerlink" title="问题分析"></a>问题分析</h1><h2 id="检查各种版本"><a href="#检查各种版本" class="headerlink" title="检查各种版本"></a>检查各种版本</h2><pre><code>仓库中 12.2 版本,部署失败后，先排查下面几种场景</code></pre>
<ul>
<li><p>仓库代码补丁，取消补丁后，重新编译部署，测试失败</p>
</li>
<li><p>debian上游的12.2 版本，64K内存页下，编译部署，测试失败</p>
</li>
<li><p>在4K内存页下,重新编译部署，测试失败</p>
</li>
<li><p>在同样属于ARM架构的飞腾服务器上测试，测试通过，排除64K内存页导致的问题，怀疑是CPU差异导致的问题</p>
<p> 看起来是由于CPU差异，导致的bug。</p>
</li>
</ul>
<h2 id="单元测试"><a href="#单元测试" class="headerlink" title="单元测试"></a>单元测试</h2><p>尝试跑一下ceph的单元测试</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">apt <span class="built_in">source</span> ceph</span><br><span class="line"><span class="built_in">cd</span> ceph-12.2.11+dfsg1.2</span><br><span class="line">sudo apt build-dep .  <span class="comment"># 安装编译依赖</span></span><br><span class="line">./do_cmake.sh</span><br><span class="line"><span class="built_in">cd</span> build</span><br><span class="line">make -j12 unittest_crc32c  <span class="comment">#编译单元测试用例</span></span><br><span class="line">bin/unittest_crc32c    <span class="comment">#执行单元测试用例</span></span><br><span class="line"><span class="comment">#最终结果中，可以看到是有两个用例执行不通过的</span></span><br><span class="line">[  FAILED  ] 2 tests, listed below:</span><br><span class="line">[  FAILED  ] Crc32c.Big</span><br><span class="line">[  FAILED  ] Crc32c.Performance</span><br></pre></td></tr></table></figure>
<p>可以确认是ceph中最基本的crc的校验代码有问题</p>
<h2 id="代码分析"><a href="#代码分析" class="headerlink" title="代码分析"></a>代码分析</h2><h3 id="CPU对比"><a href="#CPU对比" class="headerlink" title="CPU对比"></a>CPU对比</h3><p>前面测试过程中讲到，飞腾服务器运行正常，鲲鹏服务器运行异常，那么我们着重排查一下两个芯片差异。</p>
<p>从海思以及飞腾的官网中了解到，Kunpeng920 是ARMV8.2架构，FT2000+是ARMV8.0架构。更详细的资料目前没有获取到。</p>
<h3 id="源码-cmake-modules-SIMDext-cmake"><a href="#源码-cmake-modules-SIMDext-cmake" class="headerlink" title="源码 cmake/modules/SIMDext.cmake"></a>源码 cmake/modules/SIMDext.cmake</h3><p>编译参数定义是在 cmake/modules/SIMDext.cmake 文件中，针对arm64场景的crc实现，定义了编译器的参数和实现代码，关于crc和crypto相关代码如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 检查gcc编译器是否成功编译，HAVE_ARMV8_CRC中保存FALSE 或者TRUE</span></span><br><span class="line">check_cxx_source_compiles(<span class="string">&quot;</span></span><br><span class="line"><span class="string">#define CRC32CX(crc, value) ....&quot;</span> HAVE_ARMV8_CRC)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 检查gcc编译器是否成功编译， HAVE_ARMV8_CRYPTO中保存FALSE 或者TRUE</span></span><br><span class="line">check_cxx_source_compiles(<span class="string">&quot;</span></span><br><span class="line"><span class="string">asm(\&quot;.arch_extension crypto\&quot;) .....&quot;</span> HAVE_ARMV8_CRYPTO)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 检查编译器是否支持armv8-a  crc  crypto 架构参数</span></span><br><span class="line">CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_MARCH)</span><br><span class="line"></span><br><span class="line"># don&#x27;t believe only the -march support; gcc 4.8.5 on RHEL/CentOS says</span><br><span class="line"># it supports +crc but hasn&#x27;t got the intrinsics or arm_acle.h. Test for</span><br><span class="line"><span class="meta"># the actual presence of one of the intrinsic functions.</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 检查gcc编译器是否成功编译，HAVE_ARMV8_CRC_CRYPTO_INTRINSICS中保存FALSE 或者TRUE</span></span><br><span class="line"><span class="keyword">if</span>(HAVE_ARMV8_CRC_CRYPTO_MARCH)</span><br><span class="line">check_cxx_source_compiles(<span class="string">&quot;</span></span><br><span class="line"><span class="string">#include &lt;inttypes.h&gt; ...... &quot;</span> HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)</span><br><span class="line">endif()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)</span><br><span class="line">message(STATUS <span class="string">&quot; aarch64 crc+crypto intrinsics supported&quot;</span>)</span><br><span class="line"><span class="built_in">set</span>(ARMV8_CRC_COMPILE_FLAGS <span class="string">&quot;$&#123;ARMV8_CRC_COMPILE_FLAGS&#125; -march=armv8-a+crc+crypto&quot;</span>)</span><br><span class="line">endif()</span><br></pre></td></tr></table></figure>
<h3 id="cmake分析"><a href="#cmake分析" class="headerlink" title="cmake分析"></a>cmake分析</h3><p>Kunpeng920上执行cmake结果<br>aarch64 crc extensions supported<br>aarch64 crypto extensions supported<br>– Performing Test HAVE_ARMV8_CRC_CRYPTO_INTRINSICS - Failed</p>
<p>FT 2000+ 上执行cmake结果<br>aarch64 crc extensions supported<br>aarch64 crypto extensions supported<br>– Performing Test HAVE_ARMV8_CRC_CRYPTO_INTRINSICS - Failed</p>
<h3 id="源码src-common-crc32c-aarch64-c"><a href="#源码src-common-crc32c-aarch64-c" class="headerlink" title="源码src/common/crc32c_aarch64.c"></a>源码src/common/crc32c_aarch64.c</h3><p>查看crc实现代码 src/common/crc32c_aarch64.c，发现调用的是汇编crc代码</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> HAVE_ARMV8_CRC_CRYPTO_INTRINSICS</span></span><br><span class="line">......</span><br><span class="line"><span class="comment">//硬件实现crc32算法</span></span><br><span class="line">crc0 = __crc32cd(crc, *(<span class="keyword">const</span> <span class="keyword">uint64_t</span> *)buffer);</span><br><span class="line">crc1 = <span class="number">0</span>;</span><br><span class="line">crc2 = <span class="number">0</span>;</span><br><span class="line">buffer += <span class="keyword">sizeof</span>(<span class="keyword">uint64_t</span>);</span><br><span class="line"></span><br><span class="line">CRC32C7X3X8(<span class="number">0</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">1</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">2</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">3</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">4</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">5</span>);</span><br><span class="line"></span><br><span class="line">crc = __crc32cd(crc2, *(<span class="keyword">const</span> <span class="keyword">uint64_t</span> *)buffer);</span><br><span class="line">crc1 = __crc32cd(<span class="number">0</span>, t1);</span><br><span class="line">crc ^= crc1;</span><br><span class="line">crc0 = __crc32cd(<span class="number">0</span>, t0);</span><br><span class="line">crc ^= crc0;</span><br><span class="line"></span><br><span class="line">........</span><br><span class="line"><span class="meta">#<span class="meta-keyword">else</span> <span class="comment">/* !HAVE_ARMV8_CRC_CRYPTO_INTRINSICS */</span></span></span><br><span class="line"><span class="comment">//汇编实现crc32算法</span></span><br><span class="line">__asm__(<span class="string">&quot;mov x16, #0xf38a \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;movk x16, #0xe417, lsl 16 \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov v1.2d[0], x16 \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov x16, #0x8014 \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;movk x16, #0x8f15, lsl 16 \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov v0.2d[0], x16 \n\t&quot;</span></span><br><span class="line">:::<span class="string">&quot;x16&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> ((length -= <span class="number">1024</span>) &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">PREF1KL2(<span class="number">1024</span>*<span class="number">3</span>);</span><br><span class="line">__asm__(<span class="string">&quot;crc32cx %w[c0], %w[c], %x[v]\n\t&quot;</span></span><br><span class="line">:[c0]<span class="string">&quot;=r&quot;</span>(crc0):[c]<span class="string">&quot;r&quot;</span>(crc), [v]<span class="string">&quot;r&quot;</span>(*(<span class="keyword">const</span> <span class="keyword">uint64_t</span> *)buffer):);</span><br><span class="line">crc1 = <span class="number">0</span>;</span><br><span class="line">crc2 = <span class="number">0</span>;</span><br><span class="line">buffer += <span class="keyword">sizeof</span>(<span class="keyword">uint64_t</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">0</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">1</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">2</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">3</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">4</span>);</span><br><span class="line">CRC32C7X3X8(<span class="number">5</span>);</span><br><span class="line"></span><br><span class="line">buffer += <span class="number">42</span>*<span class="number">3</span>*<span class="keyword">sizeof</span>(<span class="keyword">uint64_t</span>);</span><br><span class="line">PREF1KL1(<span class="number">1024</span>);</span><br><span class="line">__asm__(<span class="string">&quot;mov v2.2d[0], %x[c1] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;pmull v2.1q, v2.1d, v0.1d \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov v3.2d[0], %x[c0] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;pmull v3.1q, v3.1d, v1.1d \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;crc32cx %w[c], %w[c2], %x[v] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov %x[c1], v2.2d[0] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;crc32cx %w[c1], wzr, %x[c1] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;eor %w[c], %w[c], %w[c1] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;mov %x[c0], v3.2d[0] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;crc32cx %w[c0], wzr, %x[c0] \n\t&quot;</span></span><br><span class="line"><span class="string">&quot;eor %w[c], %w[c], %w[c0] \n\t&quot;</span></span><br><span class="line">:[c1]<span class="string">&quot;+r&quot;</span>(crc1), [c0]<span class="string">&quot;+r&quot;</span>(crc0), [c2]<span class="string">&quot;+r&quot;</span>(crc2), [c]<span class="string">&quot;+r&quot;</span>(crc)</span><br><span class="line">:[v]<span class="string">&quot;r&quot;</span>(*((<span class="keyword">const</span> <span class="keyword">uint64_t</span> *)buffer)));</span><br><span class="line">buffer += <span class="keyword">sizeof</span>(<span class="keyword">uint64_t</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span> <span class="comment">/* HAVE_ARMV8_CRC_CRYPTO_INTRINSICS */</span></span></span><br></pre></td></tr></table></figure>
<p>从源代码分析结果来看，当 <code>HAVE_ARMV8_CRC_CRYPTO_INTRINSICS</code> 为<code>True</code>时，直接使用硬件CRC算法，当 <code>HAVE_ARMV8_CRC_CRYPTO_INTRINSICS</code> 为<code>False</code>时，使用汇编指令实现CRC算法。</p>
<p>由于KP和FT上cmake结果中 <code>HAVE_ARMV8_CRC_CRYPTO_INTRINSICS</code> 都是<code>False</code>，那么KP 和FT 都是通过汇编指令实现的crc算法，只是在KP上部分单元测试场景失败，FT上单元测试全部通过。</p>
<p>所以接下来看下KP和FT是否都支持硬件CRC算法。</p>
<h3 id="GCC参数对比"><a href="#GCC参数对比" class="headerlink" title="GCC参数对比"></a>GCC参数对比</h3><p>我们分析一下编译参数 <code>-march=armv8-a+crc+crypto</code>，分别在<code>Kunpeng920</code>和<code>FT2000+</code>上执行命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">echo | gcc -dM -E - -march&#x3D;armv8-a+crypto</span><br><span class="line">echo | gcc -dM -E - -march&#x3D;armv8-a+crc</span><br><span class="line">echo | gcc -dM -E - -march&#x3D;armv8-a+crc+crypto</span><br></pre></td></tr></table></figure>
<p>对比结果差异，发现 </p>
<p><code>crypto</code>参数定义了</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __ARM_FEATURE_AES 1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __ARM_FEATURE_CRYPTO 1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __ARM_FEATURE_SHA2 1</span></span><br></pre></td></tr></table></figure>
<p><code>crc</code>参数定义了</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __ARM_FEATURE_CRC32 1</span></span><br></pre></td></tr></table></figure>
<p>可以确定两款CPU场景下都是支持 crc和ctypto参数的。见附录2</p>
<h3 id="patch"><a href="#patch" class="headerlink" title="patch"></a>patch</h3><p>只需要保证 <code>HAVE_ARMV8_CRC_CRYPTO_INTRINSICS</code> 为<code>True</code>，就可以直接使用硬件crc算法，那么可以之就修改cmake文件，<code>cmake/modules/SIMDext.cmake</code>，将之前无法编译通过的程序改为如下代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(HAVE_ARMV8_CRC_CRYPTO_MARCH)</span><br><span class="line">check_cxx_source_compiles(<span class="string">&quot;</span></span><br><span class="line"><span class="string">#include &lt;inttypes.h&gt;</span></span><br><span class="line"><span class="string">int main() &#123; return 0; &#125;</span></span><br><span class="line"><span class="string">&quot;</span> HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)</span><br><span class="line">endif()</span><br></pre></td></tr></table></figure>
<h1 id="实验验证"><a href="#实验验证" class="headerlink" title="实验验证"></a>实验验证</h1><p>打上补丁后，重新做单元测试，测试通过</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">Running main() from gmock_main.cc</span><br><span class="line">[==========] Running 9 tests from 1 <span class="built_in">test</span> <span class="keyword">case</span>.</span><br><span class="line">[----------] Global <span class="built_in">test</span> environment set-up.</span><br><span class="line">[----------] 9 tests from Crc32c</span><br><span class="line">[ RUN      ] Crc32c.Small</span><br><span class="line">[       OK ] Crc32c.Small (0 ms)</span><br><span class="line">[ RUN      ] Crc32c.PartialWord</span><br><span class="line">[       OK ] Crc32c.PartialWord (0 ms)</span><br><span class="line">[ RUN      ] Crc32c.Big</span><br><span class="line">[       OK ] Crc32c.Big (1 ms)</span><br><span class="line">[ RUN      ] Crc32c.Performance</span><br><span class="line">[       OK ] Crc32c.Performance (5931 ms)</span><br><span class="line">[ RUN      ] Crc32c.Range</span><br><span class="line">[       OK ] Crc32c.Range (0 ms)</span><br><span class="line">[ RUN      ] Crc32c.RangeZero</span><br><span class="line">[       OK ] Crc32c.RangeZero (0 ms)</span><br><span class="line">[ RUN      ] Crc32c.RangeNull</span><br><span class="line">[       OK ] Crc32c.RangeNull (0 ms)</span><br><span class="line">[ RUN      ] Crc32c.zeros_performance_compare</span><br><span class="line">[       OK ] Crc32c.zeros_performance_compare (68 ms)</span><br><span class="line">[ RUN      ] Crc32c.zeros_performance</span><br><span class="line">[       OK ] Crc32c.zeros_performance (954 ms)</span><br><span class="line">[----------] 9 tests from Crc32c (6954 ms total)</span><br><span class="line"></span><br><span class="line">[----------] Global <span class="built_in">test</span> environment tear-down</span><br><span class="line">[==========] 9 tests from 1 <span class="built_in">test</span> <span class="keyword">case</span> ran. (6954 ms total)</span><br><span class="line">[  PASSED  ] 9 tests.</span><br></pre></td></tr></table></figure>
<h1 id="附录1-crc介绍"><a href="#附录1-crc介绍" class="headerlink" title="附录1 crc介绍"></a>附录1 <a target="_blank" rel="noopener" href="https://baike.baidu.com/item/CRC/1453359">crc介绍</a></h1><h1 id="附录2-GCC-ARM扩展参数介绍"><a href="#附录2-GCC-ARM扩展参数介绍" class="headerlink" title="附录2 GCC-ARM扩展参数介绍"></a>附录2 <a target="_blank" rel="noopener" href="https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html">GCC-ARM扩展参数介绍</a></h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">armv8-a</span><br><span class="line">    +crc： The Cyclic Redundancy Check (CRC) instructions.</span><br><span class="line">    +simd： The ARMv8-A Advanced SIMD and floating-point instructions.</span><br><span class="line">    +crypto：The cryptographic instructions.</span><br></pre></td></tr></table></figure>
<h1 id="附录3-鲲鹏和飞腾官网资料"><a href="#附录3-鲲鹏和飞腾官网资料" class="headerlink" title="附录3 鲲鹏和飞腾官网资料"></a>附录3 鲲鹏和飞腾官网资料</h1><p><a target="_blank" rel="noopener" href="https://www.hisilicon.com/cn/products/Kunpeng/Huawei%20Kunpeng%20920">Kunpeng 920</a></p>
<p><a target="_blank" rel="noopener" href="https://www.phytium.com.cn/article/20">FT-2000+/64</a>  </p>
<p><a target="_blank" rel="noopener" href="https://documentation-service.arm.com/static/6026a5f72c40871302af4485?token=">ARM官方资料</a></p>
<h1 id="附录4-github上的patch"><a href="#附录4-github上的patch" class="headerlink" title="附录4 github上的patch"></a>附录4 <a target="_blank" rel="noopener" href="https://github.com/ceph/ceph/pull/24169/files">github上的patch</a></h1>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/ceph/" rel="tag"># ceph</a>
              <a href="/tags/crc/" rel="tag"># crc</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/11/19/uos-search-file-in-deb/" rel="prev" title="uos-search-file-in-deb">
      <i class="fa fa-chevron-left"></i> uos-search-file-in-deb
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/05/10/lfs-notebook-01/" rel="next" title="lfs-notebook-01">
      lfs-notebook-01 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0"><span class="nav-number">1.</span> <span class="nav-text">问题描述</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%97%AE%E9%A2%98%E5%88%86%E6%9E%90"><span class="nav-number">2.</span> <span class="nav-text">问题分析</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A3%80%E6%9F%A5%E5%90%84%E7%A7%8D%E7%89%88%E6%9C%AC"><span class="nav-number">2.1.</span> <span class="nav-text">检查各种版本</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95"><span class="nav-number">2.2.</span> <span class="nav-text">单元测试</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-number">2.3.</span> <span class="nav-text">代码分析</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#CPU%E5%AF%B9%E6%AF%94"><span class="nav-number">2.3.1.</span> <span class="nav-text">CPU对比</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%BA%90%E7%A0%81-cmake-modules-SIMDext-cmake"><span class="nav-number">2.3.2.</span> <span class="nav-text">源码 cmake&#x2F;modules&#x2F;SIMDext.cmake</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#cmake%E5%88%86%E6%9E%90"><span class="nav-number">2.3.3.</span> <span class="nav-text">cmake分析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%BA%90%E7%A0%81src-common-crc32c-aarch64-c"><span class="nav-number">2.3.4.</span> <span class="nav-text">源码src&#x2F;common&#x2F;crc32c_aarch64.c</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GCC%E5%8F%82%E6%95%B0%E5%AF%B9%E6%AF%94"><span class="nav-number">2.3.5.</span> <span class="nav-text">GCC参数对比</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#patch"><span class="nav-number">2.3.6.</span> <span class="nav-text">patch</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%9E%E9%AA%8C%E9%AA%8C%E8%AF%81"><span class="nav-number">3.</span> <span class="nav-text">实验验证</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%99%84%E5%BD%951-crc%E4%BB%8B%E7%BB%8D"><span class="nav-number">4.</span> <span class="nav-text">附录1 crc介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%99%84%E5%BD%952-GCC-ARM%E6%89%A9%E5%B1%95%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D"><span class="nav-number">5.</span> <span class="nav-text">附录2 GCC-ARM扩展参数介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%99%84%E5%BD%953-%E9%B2%B2%E9%B9%8F%E5%92%8C%E9%A3%9E%E8%85%BE%E5%AE%98%E7%BD%91%E8%B5%84%E6%96%99"><span class="nav-number">6.</span> <span class="nav-text">附录3 鲲鹏和飞腾官网资料</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%99%84%E5%BD%954-github%E4%B8%8A%E7%9A%84patch"><span class="nav-number">7.</span> <span class="nav-text">附录4 github上的patch</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Movie</p>
  <div class="site-description" itemprop="description">学习，记录，分享，收获</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">14</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Movie</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'bx3R5BB7VYCe0Yu5f4PF2Ako-gzGzoHsz',
      appKey     : '24eOkgM1v8hYTlnAO3C2eG3n',
      placeholder: "欢迎留言评论",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
